from dataclasses import dataclass

from graia.ariadne import Ariadne
from graia.amnesia.message import MessageChain
from graia.ariadne.message.element import At

import utils.message


@dataclass
class CommandSource:
    from_id: int
    group_id: int = 0

    async def reply(self, app: Ariadne, message: str | MessageChain):
        message_chain = MessageChain(message)
        if self.group_id == 0:
            await utils.message.send_friend_message(app, self.from_id, message_chain)
            return
        message_chain = MessageChain([At(self.from_id), "\n"] + list(message_chain))
        await utils.message.send_group_message(app, self.group_id, message_chain)
